package com.todo.event.activity.iface.backend.request;

import com.todo.common.common.entity.CurrentStaff;
import com.todo.common.utils.StringUtils;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import org.apache.commons.collections4.CollectionUtils;

import java.util.List;

/**
 * @author azhebuxing
 * @date 2025/1/10 22:22
 * @description
 */
@Data
public class UpdateEventDecisionReq {

private CurrentStaff _staff;

    @Schema(title = "主键id", description = "主键id")
    private Long id;

    @Schema(title = "决策名称", description = "决策名称")
    private String name;

    @Schema(title = "决策描述", description = "决策描述")
    private String desc;

    @Schema(title = "决策类型", description = "决策类型 单事件、多事件")
    private Integer decisionType;

    @Schema(title = "首事件", description = "首事件")
    private String firstEvent;

    @Schema(title = "首事件规则", description = "首事件规则")
    private List<FieldRule> firstEventRule;

    @Schema(title = "间隔时间", description = "间隔时间 多事件存在")
    private Integer intervalTime;

    @Schema(title = "第二事件", description = "第二事件")
    private String secondEvent;

    @Schema(title = "第二事件规则", description = "第二事件规则")
    private List<FieldRule> secondEventRule;

    @Schema(title = "是否使用唯一标识", description = "是否使用唯一标识")
    private Boolean useUnique;

    public boolean baseCheck() {
        if (StringUtils.isBlank(name) || StringUtils.isBlank(firstEvent)){
            return false;
        }
        if (CollectionUtils.isNotEmpty(firstEventRule)){
            for (FieldRule fieldRule : firstEventRule){
                if (fieldRule.getFieldName() == null || fieldRule.getOperateEnum() == null || fieldRule.getOperateValue() == null || fieldRule.getTypeEnum() == null){
                    return false;
                }
            }
        }
        if (CollectionUtils.isNotEmpty(secondEventRule)){
            for (FieldRule fieldRule : secondEventRule){
                if (fieldRule.getFieldName() == null || fieldRule.getOperateEnum() == null || fieldRule.getOperateValue() == null || fieldRule.getTypeEnum() == null){
                    return false;
                }
            }
        }
        return true;
    }


    @Data
    public static class FieldRule {

        @Schema(title = "字段名称", description = "字段名称")
        private String fieldName;

        @Schema(title = "字段类型", description = "字段类型")
        private Integer typeEnum;

        @Schema(title = "操作类型", description = "操作类型")
        private Integer operateEnum;

        @Schema(title = "操作值", description = "操作值")
        private String operateValue;
    }
}
